;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This is the small testing tool which will use the return variable 
;truth assignment to test the satisfiability of input list
;To use it, just (load "checker.txt")
;and (checksatisfy test) assuming your funtion is called "satisfy"
;
;
;

(load "utility.txt")

(define dogetsymbol
	(lambda(var varlist)
		(if (is_not var)
			(not(cdr (assoc (cadr var) varlist)))
			;(cdr (assoc (cadr var) varlist));deliberately left for debugging
			(cdr (assoc var varlist))
		)
	)
)

(define snapvarlist
	(lambda (var varlist)
		(if (is_not var)
			(assoc (cadr var) varlist)
			(assoc var varlist)
		)
	)
)

(define checksymbol
	(lambda (sym varlist)
		(dogetsymbol sym varlist)
	)
)

(define checkterm
	(lambda (term varlist)
		;(begin (pp (list "checkterm term=" term "varlist=" varlist))
		(if (null? term)
			#f
			(if (or(is_or term)(is_and term))
			   	(checkterm (cdr term) varlist)
				(if (is_symbol term)
					(checksymbol term varlist)
					(or (checksymbol (car term) varlist)
						(checkterm (cdr term) varlist))
				)
			)
		);)
	)
)
					
	
(define outputerror
	(lambda (term varlist)
		;(begin (pp(list "outputerror term=" term "varlist=" varlist))
		(if (null? term)
			'()
			(if (or(is_or term)(is_and term))
				(outputerror(cdr term) varlist)
				(if (is_symbol term)
					(snapvarlist term varlist)
					(cons (snapvarlist (car term) varlist)
						(outputerror (cdr term)varlist))
				)
			)
		);)
	)
)
								
					
				
				

(define stepbystep
	(lambda (ls varlist)
		(if (null? ls)
			(pp "congratulations!")
			(if (checkterm (car ls) varlist)
				(stepbystep (cdr ls) varlist)
				(begin 
					(pp (list "there is an error term "(car ls)))
					(outputerror (car ls) varlist)
				)
			)
		)
	)
)

(define checker
	(lambda (ls varlist)
		(if (not(boolean? varlist))
			(stepbystep (cdr ls) varlist)
			(pp (list "so you mean it is unsatisfiable, do you expect me to clarify it? no way!"))
				
		)
	)
)
	
;a wrapper for using , you should use this
(define checksatisfy
	(lambda (ls)
		(checker ls (satisfy ls))
	)
)		
